package wjl.project.dubboelabauthconsumer.SecurityConfig;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import wjl.project.dubboelabauthconsumer.Entity.EUser;
import wjl.project.dubboelabauthconsumer.Repository.EUserRepository;

import javax.annotation.Resource;
@Service
public class SecurityUserDetailService implements UserDetailsService {
    @Resource
    EUserRepository eUserRepository;

    @Override
    public UserDetails loadUserByUsername(String phone) throws UsernameNotFoundException {
        EUser user = eUserRepository.findByMobilePhone(phone).orElseThrow(()->new UsernameNotFoundException("没有找到该账号"));
        return new SecurityUser(user);
    }
}
